<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\massage\model;

class ConfigSetting extends \app\BaseModel
{
    protected $name = "massage_config_setting";
    public function getValueAttr($value, $data)
    {
        $arr = ["salesman_balance", "salesman_coach_balance", "salesman_admin_balance", "channel_balance", "channel_coach_balance", "channel_admin_balance", "coach_agent_balance", "tax_point", "user_agent_balance", "partner_coach_balance", "partner_admin_balance"];
        if(isset($data["field_type"])) {
            if($data["field_type"] == 3 || in_array($data["key"], $arr)) {
                $value = floatval($value);
            } elseif($data["field_type"] == 1) {
                $value = (int) $value;
            }
        }
        return $value;
    }
    public function dataList($dis, $page)
    {
        $data = $this->where($dis)->order("status desc,id desc")->paginate($page)->toArray();
        return $data;
    }
    public function initData($uniacid, $key_arr = [])
    {
        $dataPath = APP_PATH . "massage/info/ConfigSetting.php";
        $data = (include $dataPath);
        $key = "config_setting_init_data";
        incCache($key, 1, $uniacid, 99);
        $value = getCache($key, $uniacid);
        if($value == 1) {
            foreach ($data as $v) {
                if(!empty($key_arr) && !in_array($v["key"], $key_arr)) {
                } else {
                    $dis = ["uniacid" => $uniacid, "key" => $v["key"]];
                    $find = $this->where($dis)->find();
                    if(empty($find)) {
                        $dis["text"] = $v["text"];
                        $dis["value"] = $v["default_value"];
                        $dis["default_value"] = $v["default_value"];
                        $dis["field_type"] = $v["field_type"];
                        $this->insert($dis);
                    }
                }
            }
        }
        decCache($key, 1, $uniacid, 90);
        return true;
    }
    public function dataInfo($uniacid, $key_arr = [])
    {
        if(empty($uniacid)) {
            return false;
        }
      /*  print_r(func_get_args());
        exit;*/
        $dis[] = ["uniacid", "=", $uniacid];
        if(!empty($key_arr)) {
            $dis[] = ["key", "in", $key_arr];
        }
        $data = $this->where($dis)->select()->toArray();
        foreach ($data as $v) {
            $arr[$v["key"]] = $v["value"];
        }
        return !empty($arr) ? $arr : "";
    }
    public function dataUpdate($arr, $uniacid)
    {
        if(!empty($arr)) {
            foreach ($arr as $k => $value) {
                if("order_rules" == $k) {
                    $config_model = new MassageConfig();
                    $config_model->dataInfo(["uniacid" => $uniacid]);
                    $config_model->dataUpdate(["uniacid" => $uniacid], [$k => $value]);
                } else {
                    $dis = ["uniacid" => $uniacid, "key" => $k];
                    $this->where($dis)->update(["value" => $value]);
                }
            }
        }
        return true;
    }
}

?>